package com.stone.design.practice.classTest;

import java.util.HashMap;
import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 5/24/18 22:54
 * @email redsstone@163.com
 */
public class ClassTest {

    public static void main(String[] args) {
        try {
            Class<?> aClass = Class.forName("com.stone.design.practice.test.Test");

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        // 顺序执行 count2 先被赋值1 然后又被赋值0 所以输出是0
        // 虽然count1也是这样，但是后来没有对count1赋值，因为之前已经对count1变量定义了一次了
        SingleTon singleTon = SingleTon.getInstance();
        System.out.println("count1=" + singleTon.count1);
        System.out.println("count2=" + singleTon.count2);

        for (;;) {
            System.out.println("please input string");
            Scanner scanner = new Scanner(System.in);
            String s = scanner.nextLine();
            System.out.println("输入的字符串： " + s);
            String regex = "^this\\s+is\\s+stone$";

            boolean isMatch = Pattern.matches(regex, s);
            System.out.println("是否匹配：" + isMatch);
        }

    }
}


class SingleTon {

    // 顺序执行
    private static SingleTon singleTon = new SingleTon();
    public static int count1;
    public static int count2 = 0;

    private SingleTon() {
        count1++;
        count2++;
    }

    public static SingleTon getInstance() {
        return singleTon;
    }
}
